var util = require('../../utils/util.js');
const ttParse = require('../../ttParse/ttParse.js');
var app = getApp();

Page({
  data: {
    indicatorDots: true,
    autoplay: true,
    interval: 4000,
    duration: 600,
    swiper_w: 0,
    swiper_h: 0,
    swiperImages: '',
    detailData: '',
    isIphone_X: false,
  },

  onLoad: function (data) {
    var that = this;

    tt.showLoading({
      title: '加载中',
      mask: 'true'
    });

    this.setData({
      isIphone_x: app.isIphone_x,
      screen_w: app.screen_w,
      screen_h: app.screen_h,
      swiper_w: app.screen_w,
      swiper_h: app.screen_w
    })

    that.load(data.topicid)
  },

  

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  onShow: function () {
    
  },

  load: function (topicid) {
    var that = this;
    var params = {
      publickey: util.publiccode,
      ac: "topicdetail",
      topicid: topicid

    };
    console.log("动态详情请求参数：", params);
    //动态详情
    util.api({
      data: params,
      success: function (responseData) {
        var data = responseData.data;
        console.log("啊啊啊啊啊详情：", data);
        //处理message  
        var detailMessage = data.message;
        console.log("detailMessage: ", detailMessage);
        ttParse.ttParse('messagehtml', 'html', detailMessage, that, 5)
        that.setData({
          detailData: data,
          swiperImages: data.photoscbk
        });
       tt.hideLoading();
      }
    });
  },


  clickImg: function (e) {
    
      var imgListType = e.currentTarget.dataset.imglist;
      var imgList = [];
      var photo = this.data.detailData.photoscbk;
      for (var i = 0; i < photo.length; i++) {
        imgList = imgList.concat([photo[i].photo]);
      }      
      console.log(imgList);
      tt.previewImage({
        current: e.currentTarget.dataset.imgsrc,
        urls: imgList
      })
  },


  makeCallPhone: function (e) {
    var phoneNum = e.currentTarget.dataset.number;
    console.log("phoneNum:" + phoneNum);
    tt.makePhoneCall({
      phoneNumber: phoneNum,
      success: function (e) {
        console.log("make call success:", JSON.stringify(e));
      },
      fail: function (e) {
        console.log("make call fail:", JSON.stringify(e));
      }
    })
  }

})